package com.songpeng.demo;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;

/**
 * @author 86137
 */
public class UrlParamVerticle extends AbstractVerticle {

  Router router = Router.router(vertx);

  @Override
  public void start(Promise<Void> startPromise) throws Exception {
    router.get("/").handler(req -> {
      var username = req.request().getParam("username");
      var realName = req.request().getParam("realName");
      var params = new JsonObject();
      params.put("username", username);
      params.put("realName", realName);
      req.response().putHeader("content-type", "text/plain")
        .end(params.toBuffer());
    });
    vertx.createHttpServer().requestHandler(router).listen(8888, http -> {
      if (http.succeeded()) {
        startPromise.complete();
        ;
      } else {
        startPromise.fail(http.cause());
      }
    });
  }
}
